package cn.edu.shiep.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import cn.edu.shiep.model.User;

@Repository
public class UserDao extends BaseDao<User, Integer> {

	@SuppressWarnings("unchecked")
	public List<User> getAll() {
		String hql = "from User user ";
		Query query = createQuery(hql);
		return query.list();
	}

	// public User findByWorkNumber(String workNumber) {
	// String hql = "from User u where u.workNumber=?";
	// Query query = createQuery(hql).setString(0, workNumber);
	// return (User) query.uniqueResult();
	// }

	// public User findById(Integer userId) {
	// String hql = "from User u where u.id=?";
	// Query query = getSession().createQuery(hql).setInteger(0, userId);
	// return (User) query.uniqueResult();
	// }

	// @SuppressWarnings("unchecked")
	// public List<User> findByKeyWithPaginate(Integer departmentId,
	// String keyWord, PageInfo pageInfo) {
	// Criteria ctr = getCriteriaWithRestrions(departmentId, keyWord, pageInfo);
	// ctr.setFirstResult(pageInfo.getStart());
	// ctr.setMaxResults(pageInfo.getPageSize());
	// Criteria rowCountCtr = getCriteriaWithRestrions(departmentId, keyWord,
	// pageInfo);
	// rowCountCtr.setProjection(Projections.rowCount());
	// pageInfo.setTotalSize((Long) rowCountCtr.uniqueResult());
	// return ctr.list();
	// }
	//
	// private Criteria getCriteriaWithRestrions(Integer departmentId,
	// String keyWord, PageInfo pageInfo) {
	// Criteria criteria = getExampleCriteria();
	// if(departmentId != null) {
	// criteria.add(Restrictions.eq("department.id", departmentId));
	// }
	// Disjunction dis = Restrictions.disjunction();
	// dis.add(Restrictions.like("name", keyWord, MatchMode.ANYWHERE));
	// dis.add(Restrictions.like("workNumber", keyWord, MatchMode.ANYWHERE));
	// dis.add(Restrictions.like("phoneNumber", keyWord, MatchMode.ANYWHERE));
	// dis.add(Restrictions.like("serialNumber", keyWord, MatchMode.ANYWHERE));
	// dis.add(Restrictions.like("imsi", keyWord, MatchMode.ANYWHERE));
	// dis.add(Restrictions.like("email", keyWord, MatchMode.ANYWHERE));
	// criteria.add(dis);
	// return criteria;
	// }

	// @SuppressWarnings("unchecked")
	// public List<User> findByDepartment(Integer departmentId) {
	// String hql = "from User user where user.department.id = ?";
	// Query query = createQuery(hql).setInteger(0, departmentId);
	// return query.list();
	// }
}
